import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFactory;
import java.io.IOException;
import java.util.Scanner;

public class main {
    public static void main(String[] args) throws IOException, WebSocketException {
        WebSocketFactory factory = new WebSocketFactory();
        WebSocket ws = factory.createSocket("ws://xxxx");
        ws.addListener(new WebSocketAdapter() {
            @Override
            public void onTextMessage(WebSocket websocket, String message) throws Exception {
                System.out.println("收到消息：" + message);
            }
        });
        ws.connect();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("输入信息(exit为退出): ");
            String input = scanner.nextLine();
            if (input.equalsIgnoreCase("exit")) {
                break;
            }
            ws.sendBinary(input.getBytes());
        }
        scanner.close();
    }
}
